var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2LoadManager = require("LoadManager");
var $2ConstValue = require("ConstValue");
var $2GameConfig = require("GameConfig");
var $2constant = require("constant");
var $2Globe = require("Globe");
var $2PlatformMgr = require("PlatformMgr");
var $2Platformconf = require("Platformconf");
var $2GameUser = require("GameUser");
var $2GameEvent = require("GameEvent");
var $2UIManager = require("UIManager");
var $2UIVHome = require("UIVHome");
var $2ShareMgr = require("ShareMgr");
var $2RedDotReceiving = require("RedDotReceiving");
var $2RedDotManager = require("RedDotManager");
var $2UISidebar = require("UISidebar");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_GameMain = /* */function (_cc$Component14) {
  function _ctor() {
    var _this22;
    babel_classCallCheck(this, _ctor);
    _this22 = _callSuper(this, _ctor, arguments);
    _this22.time_dt = 0;
    _this22.twoSecondTime = 0;
    return _this22;
  }
  babel_inherits(_ctor, _cc$Component14);
  return babel_createClass(_ctor, [{
    key: "onLoad",
    value: function onLoad() {
      if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
        if (window.SideBarEnter) {
          $2ConstValue.ConstValue.SidebarEnterGame = true;
        } else {
          $2ConstValue.ConstValue.SidebarEnterGame = false;
        }
        this.ttSliderBarFunc();
      }
      $2EventCenter.default.regisEvent($2EventDefine.default.EVENT_ONSHOW, this.onGameShow, this);
      $2EventCenter.default.regisEvent($2EventDefine.default.EVENT_ONHIDE, this.onGameHide, this);
      $2Globe.default.linkMouse();
      this.loadconfigs();
      $2constant.default.isipad = cc.winSize.height / cc.winSize.width < 1334 / 750;
      $2Platformconf.default.Instance;
      console.log("平台类型：", $2Platformconf.default.PlatformType);
      $2ShareMgr.default.Instance.onShareAppMessage();
      $2PlatformMgr.default.Instance().init({
        onLoginned(e) {
          var t = e.userinfo;
          var n = $2GameUser.default.getInstance();
          n.openid = t.openid;
          n.id = e.id;
          n.uid = e.uid;
          $2GameEvent.default.sendEvent("getdata", {}, function (e) {
            var t = e.data;
            n.getDatas(t);
          });
        }
      });
      $2UIManager.UIManager.getInstance().showUI($2UIVHome.default);
      this.updateNewDayInfo();
      this.initRender();
    }
  }, {
    key: "initRender",
    value: function initRender() {
      $2ConstValue.ConstValue.PlayerOnLineTime = 0;
      $2ConstValue.ConstValue.InterAdIntervalTime = 0;
    }
  }, {
    key: "onDestroy",
    value: function onDestroy() {
      $2EventCenter.default.removeEvent($2EventDefine.default.EVENT_ONSHOW, this.onGameShow, this);
      $2EventCenter.default.removeEvent($2EventDefine.default.EVENT_ONHIDE, this.onGameHide, this);
    }
  }, {
    key: "onGameShow",
    value: function onGameShow() {
      console.log("..........................回到游戏..........................");
    }
  }, {
    key: "onGameHide",
    value: function onGameHide() {
      console.log("..........................离开游戏..........................");
    }
  }, {
    key: "ttSliderBarFunc",
    value: function ttSliderBarFunc() {
      if ($2ConstValue.ConstValue.SidebarEnterGame) {
        $2EventCenter.default.postEvent($2EventDefine.default.SIDEBAR_ENTER_STATE);
        console.log("小游戏通过侧边栏进入小游戏！！！");
        $2GameUser.default.getInstance().getSidebarRewardClaimState() || $2UIManager.UIManager.getInstance().showUI($2UISidebar.default);
      } else {
        console.log("小游戏不是通过侧边栏进入的小游戏");
      }
    }
  }, {
    key: "compareVersions",
    value: function compareVersions(e, t) {
      var n = e.split(".").map(Number);
      var o = t.split(".").map(Number);
      for (var _i4 = 0; _i4 < Math.max(n.length, o.length); _i4++) {
        var _e20 = n[_i4] || 0;
        var _t9 = o[_i4] || 0;
        if (_e20 < _t9) {
          return -1;
        }
        if (_e20 > _t9) {
          return 1;
        }
      }
      return 0;
    }
  }, {
    key: "loadconfigs",
    value: function loadconfigs() {
      var e = $2LoadManager.default.getInstance();
      e.addEventListen(this.onProgress.bind(this));
      $2GameConfig.default.getInstance().initAllConfig(function () {
        e.addLoadTask($2ConstValue.ConstValue.PREFAB_UI_DIR + "UITtext", 3);
      });
    }
  }, {
    key: "initUserInfo",
    value: function initUserInfo(e) {
      console.log("info,收到服务器数据", e);
    }
  }, {
    key: "onProgress",
    value: function onProgress(e, t) {}
  }, {
    key: "update",
    value: function update(e) {
      $2EventCenter.default.postEvent($2EventDefine.default.EVENT_UPDATE, e);
      this.twoSecondTime++;
      if (this.twoSecondTime >= 2) {
        this.twoSecondTime = 0;
        $2RedDotManager.default.Instance.syncRedDotStateByType($2RedDotReceiving.eRedDotType.Desktop);
        $2RedDotManager.default.Instance.syncRedDotStateByType($2RedDotReceiving.eRedDotType.Sidebar);
        $2RedDotManager.default.Instance.syncRedDotStateByType($2RedDotReceiving.eRedDotType.Collection);
      }
      this.time_dt += e;
      if (this.time_dt > 1) {
        this.time_dt = 0;
        $2ConstValue.ConstValue.PlayerOnLineTime += 1;
        $2ConstValue.ConstValue.InterAdIntervalTime > 0 && ($2ConstValue.ConstValue.InterAdIntervalTime -= 1);
      }
    }
  }, {
    key: "showNative",
    value: function showNative() {
      this.node.getChildByName("native").active = true;
    }
  }, {
    key: "hideNative",
    value: function hideNative() {
      this.node.getChildByName("native").active = false;
    }
  }, {
    key: "updateNewDayInfo",
    value: function updateNewDayInfo() {
      if (this.isNewDay()) {
        this.updateLastLaunchDate();
        console.log("新的一天 =>>> 尽情玩耍吧");
        $2GameUser.default.getInstance().setSidebarRewardClaimState(false);
        cc.sys.os != cc.sys.OS_IOS && $2GameUser.default.getInstance().setDesktopDailyRewardClaimState(false);
      } else {
        console.log("真爱粉 =>>> 接着玩耍吧");
      }
    }
  }, {
    key: "updateLastLaunchDate",
    value: function updateLastLaunchDate() {
      var e = new Date().toLocaleDateString();
      cc.sys.localStorage.setItem("lastLaunchDate", e);
    }
  }, {
    key: "isNewDay",
    value: function isNewDay() {
      var e = cc.sys.localStorage.getItem("lastLaunchDate");
      if (e) {
        var _t10 = new Date(e);
        var _n9 = new Date();
        return _n9.getDate() !== _t10.getDate() || _n9.getMonth() !== _t10.getMonth() || _n9.getFullYear() !== _t10.getFullYear();
      }
      console.log("没有日期存储记录！");
      return true;
    }
  }]);
}(cc.Component);
def_GameMain = cc__decorate([ccp_ccclass], def_GameMain);
exports.default = def_GameMain;